package com.common.utils;

import java.io.FileInputStream;
import java.io.StringReader;
import java.io.StringWriter;

import com.common.dto.LoginAccount;
import com.common.dto.Proxy;
import com.common.dto.SnatchItem;
import com.common.dto.WebConfig;
import com.common.dto.WebNode;
import com.common.dto.WebUrl;
import com.thoughtworks.xstream.XStream;



public class XmlConfigUtil{
	
	static XStream xs = new XStream();
	static{
		xs.alias("WebConfig", WebConfig.class);
		xs.alias("WebNode", WebNode.class);
		xs.alias("SnatchItem", SnatchItem.class);
		xs.alias("WebUrl", WebUrl.class);
		xs.alias("LoginAccount", LoginAccount.class);
		xs.alias("Proxy", Proxy.class);
	}
	
	
	public static WebConfig xmlChangeNodeWeb(String xmlStr){
		WebConfig snatchWeb = new WebConfig();
		StringReader stringReader = new StringReader(xmlStr);
		xs.fromXML(stringReader, snatchWeb);
		return snatchWeb;
	}
	
	public static WebConfig xmlChangeNodeWeb(FileInputStream fileInputStream){
		WebConfig snatchWeb = new WebConfig();
		
		xs.fromXML(fileInputStream, snatchWeb);
		return snatchWeb;
	}
	
	public static String nodeWebChangeXml(WebConfig snatchWeb){
		StringWriter sw = new StringWriter();
		xs.toXML(snatchWeb, sw);
		return sw.toString();
	}
	
	
	
	
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
	}

}
